import { request1 } from './index';
import { IResponse } from './type';

// 登录请求参数
export interface ILoginAccount {
  name: string;
  password: string;
}

// 登录响应参数
export interface ILoginResult {
  id: number;
  name: string;
  token: string;
}

// 登录相关接口
enum LOGIN_URL {
  LOGIN = '/login',
  USER = '/users', // 用法: /users/1
  MENUS = '/role/', // 用法： /role/1/menu
}

export function accountLoginRequest(data: ILoginAccount) {
  return request1.post<IResponse<ILoginResult>>({
    url: LOGIN_URL.LOGIN,
    data,
  });
}

export function requestUserInfoById(id: number) {
  return request1.get<IResponse>({
    url: LOGIN_URL.USER + '/' + id,
  });
}

export function getUserMenuByRoleId(id: number) {
  return request1.get<IResponse>({
    url: LOGIN_URL.MENUS + id + '/menu',
  });
}
